import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)) + "/..")
from stock.simulatestock import *
from utils.smtp.smtp import *
from utils.utils import *
import time

def get_cur_value(code):
    url = get_cur_url(code)
    data = get_url_strdata(url)
    da = str(data).split(',')
    # print(da[1], da[2], da[3])
    return da[1], da[2], da[3]

def kdj_lohc_proc(code, sarray):
    kday = SimulateStock(code, 240, 100)
    # print(code)
    #得到历史记录
    if kday.KdjGetDF() == False:
        return
    if int(kday.df["J"][-1]) >= lmin:
        return
    # print(kday.df)
    if int(kday.df["close"][-1]) >= int(kday.df["open"][-1]):
        return
    #获取当前值
    data = get_url_strdata(get_cur_url(code))
    da = data.split(',')
    if len(da) <= 4:
        return
    o, lc, c = da[1], da[2], da[3]
    if o < lc and c > lc:
        print(code, "now", get_time())

def kdj_lohc_select():
    if work_time_check() == False:
        # print("err time")
        return
    print("*********************start**************************************")
    select_array = []
    codes = get_codes()
    for code in codes:
        kdj_lohc_proc(code, select_array)

if __name__ == "__main__":
    # kdj_lohc_select()
    while True:
        try:
            kdj_lohc_select()
        except :
            print("catch err*****************")
        else:
            pass
        time.sleep(10)
    # get_cur_value("sz159920")